//
//  YYLabel+ImagedLabel.m
//  GuardMan
//
//  Created by steven on 2016/12/26.
//  Copyright © 2016年 steven. All rights reserved.
//

#import "YYLabel+ImagedLabel.h"

@implementation YYLabel (ImagedLabel)

+ (YYLabel *)labelWithTitle:(NSString *)title imageNamed:(NSString *)imageName {
    YYLabel *label = [[YYLabel alloc] init];
    NSMutableAttributedString *text = [NSMutableAttributedString new];
    UIFont *font = [UIFont systemFontOfSize:12];
    text.yy_font = font;
    
    NSString *titleString = [NSString stringWithFormat:@"  %@", title];
    [text appendAttributedString:[[NSAttributedString alloc] initWithString:titleString attributes:nil]];
    
    UIImage *attachImage = [UIImage imageNamed:imageName];
    
    NSMutableAttributedString *attachText = [NSMutableAttributedString yy_attachmentStringWithContent:attachImage contentMode:UIViewContentModeCenter attachmentSize:attachImage.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
    
    [text insertAttributedString:attachText atIndex:0];
    
    label.attributedText = text;
    label.textColor = [UIColor whiteColor];
    
    return label;
}

+ (YYLabel *)labelWithTitle:(NSString *)title fontSize:(NSInteger)fontSize textColor:(UIColor *)textColor imageNamed:(NSString *)imageName {
    YYLabel *label = [[YYLabel alloc] init];
    NSMutableAttributedString *text = [NSMutableAttributedString new];
    UIFont *font = [UIFont systemFontOfSize:fontSize];
    text.yy_font = font;
    
    NSString *titleString = [NSString stringWithFormat:@"  %@", title];
    [text appendAttributedString:[[NSAttributedString alloc] initWithString:titleString attributes:nil]];
    
    UIImage *attachImage = [UIImage imageNamed:imageName];
    
    NSMutableAttributedString *attachText = [NSMutableAttributedString yy_attachmentStringWithContent:attachImage contentMode:UIViewContentModeCenter attachmentSize:attachImage.size alignToFont:font alignment:YYTextVerticalAlignmentCenter];
    
    [text insertAttributedString:attachText atIndex:0];
    
    label.attributedText = text;
    label.textColor = textColor;
    
    return label;
}

@end
